﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ZLDC.Common.BaseUser;
using System.Collections.Generic;
using System.Text;
using ZLDC.Common.Estate;

namespace ZLDC.Estate.TM
{
    public partial class EstateDetail : _PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                iUserName.Value = this.info.m_sUserName;
                iUserDept.Value = this.info.m_sDeptName;
                ideptid.Value = this.info.m_sDeptID;
                iuserid.Value = this.info.m_sUserID;

                btnCompetences();   // 权限控制按钮

                setUrl();

                hAllowOutsidePhotoCount.Value = ZLDC.Topo.BLL.Estate.SystemOptionBLL.GetOption("楼盘允许上传小区图数").ToString();
                hAllowRoomfigureCount.Value = ZLDC.Topo.BLL.Estate.SystemOptionBLL.GetOption("楼盘允许上传户型图数").ToString();
                DropList();
            }
        }

        private void DropList()
        {
            _Database db = new _Database("estate");
            dropdg.DataSource = ZLDC.Topo.BLL.Estate.BuildBLL.listdg(Request.QueryString["id"].ToString());
            dropdg.DataTextField = "finalName";
            dropdg.DataValueField = "id";
            dropdg.DataBind();
            ListItem item = new ListItem();
            item.Text = "请选择";
            item.Value = "0";
            dropdg.Items.Insert(0,item);
        }

        // 权限控制按钮
        private void btnCompetences()
        {
            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("申请添加栋阁"))
                hCompetencesIsAdd.Value = "1";    
        
            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("修改栋阁"))
                hCompetencesIsEdit.Value = "1";

            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("删除栋阁"))
                hCompetencesIsDel.Value = "1";

            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("申请添加别名"))
                hCompetencesIsOtherName.Value = "1";

            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("审核楼盘字典"))
                hCompetencesIsCheck.Value = "1";

            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("删除本部楼盘图片"))
                hCompetenDelPic.Value = "1";

            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("确认整理完成"))
                btnSuccess.Visible = true;                               

            if (_Utility.GetInfoBySession().m_sRoleID == "1")//系统管理员
                hRoleId.Value = _Utility.GetInfoBySession().m_sRoleID.ToString();
            
        }

        // 设置 首条 上一条 下一条 尾条 
        private void setUrl()
        {
            string id = _Request.GetString("id");               // 当前ID
            string id_list = _Request.GetString("id_list");     // 所有ID字符串
            string tagNo = _Request.GetString("tagNo");

            if (id_list.IndexOf(",") < 0)
            {
                btnFirst.Visible = false;
                btnPrev.Visible = false;
                btnNext.Visible = false;
                btnLast.Visible = false;

                return;
            }

            string[] m_sIdiList = id_list.Split(',');   // 所有ID数组
            int m_nPos = 0;

            //检查位置
            int listLength = m_sIdiList.Length;
            for (int i = 0; i < listLength; i++)
            {
                if (m_sIdiList[i] == id)
                {
                    m_nPos = i;
                    break;
                }
            }

            this.btnFirst.Attributes["onclick"] = "javascript:window.location.href='EstateDetail.aspx?tagNo=" + tagNo + "&id=" + m_sIdiList[0] + "&id_list=" + id_list + "';return false;";
            if (m_nPos != 0)
            {
                this.btnPrev.Enabled = true;
                this.btnFirst.Enabled = true;
                this.btnPrev.Attributes["onclick"] = "javascript:window.location.href='EstateDetail.aspx?tagNo=" + tagNo + "&id=" + m_sIdiList[m_nPos - 1] + "&id_list=" + id_list + "';return false;";
            }
            else
            {
                this.btnPrev.Enabled = false;
                this.btnFirst.Enabled = false;
            }
            if (m_nPos != m_sIdiList.Length - 1)
            {
                this.btnNext.Enabled = true;
                this.btnLast.Enabled = true;
                this.btnNext.Attributes["onclick"] = "javascript:window.location.href='EstateDetail.aspx?tagNo=" + tagNo + "&id=" + m_sIdiList[m_nPos + 1] + "&id_list=" + id_list + "';return false;";
            }
            else
            {
                this.btnNext.Enabled = false;
                this.btnLast.Enabled = false;
            }
            this.btnLast.Attributes["onclick"] = "javascript:window.location.href='EstateDetail.aspx?tagNo=" + tagNo + "&id=" + m_sIdiList[m_sIdiList.Length - 1] + "&id_list=" + id_list + "';return false;";
        }


    }
}
